﻿
CREATE function MaxAvailableInventory( @ProductID int ) 
returns int
as
begin
	declare @retVal int
	select @retVal = min(T2.Qty / T1.Qty)
		from dbo.ProductBuildPlan(@ProductID) as T1
			join tblInventory T2 on T1.ProductID = T2.ProductID
	return @retVal
end